import { _decorator, animation, Component, find, instantiate, Node, Prefab } from 'cc';
import { Plant } from './Plant';
import { Sun } from './Sun';
const { ccclass, property } = _decorator;

@ccclass('SunFlower')
export class SunFlower extends Plant {
    @property(Number)
    produceDuration: number = 5;
    private produceTimer:number=0;
    anim:animation.AnimationController=null;
    @property(Prefab)
    sunPrefab:Prefab=null;
    private delataTime:number;
    protected onLoad(): void {
        this.anim=this.getComponent(animation.AnimationController);
    }
    update(deltaTime: number): void {
        super.update(deltaTime);
        this.delataTime=deltaTime;
    }
    enableUpdate(){
        super.enableUpdate();
        this.produceTimer+=this.delataTime;
        if(this.produceTimer>=this.produceDuration){
            this.anim.setValue('isGlowing',true);
            this.produceTimer=0;
        }
    }
    produceSun() {
        let sunNode=instantiate(this.sunPrefab);
        sunNode.parent=find("Canvas/ForeGround");
        sunNode.setPosition(this.node.position);
        sunNode.getComponent(Sun).jumpTo();
    }
}


